package com.hyxt.provider;

import com.alibaba.dubbo.config.annotation.Service;
import com.hyxt.DO.*;
import com.hyxt.api.MysqlDataService;
import com.hyxt.dao.LoginfoMapper;
import com.hyxt.dao.LogoperaMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

@Service(interfaceClass = MysqlDataService.class,version = "1.0.0")
public class MysqlDataServiceImpl implements MysqlDataService {
    @Autowired
    private LoginfoMapper loginfoMapper;
    @Autowired
    private LogoperaMapper logoperaMapper;

    @Override
    public int insert(DataRecode record) throws Exception{
        if(record instanceof Loginfo){
            return loginfoMapper.insert((Loginfo)record);
        }else if(record instanceof Logopera){
            return logoperaMapper.insert((Logopera)record);
        }else{
            throw new Exception("");
        }
    }

    @Override
    public DataRecode selectByPrimaryKey(DataRecode record) throws Exception{
        if(record instanceof Loginfo){
            return loginfoMapper.selectByPrimaryKey(((Loginfo) record).getId());
        }else if(record instanceof Logopera){
            return logoperaMapper.selectByPrimaryKey(((Logopera) record).getId());
        }else{
            throw new Exception("");
        }
    }

    @Override
    public int updateByPrimaryKeySelective(DataRecode record) throws Exception{
        if(record instanceof Loginfo){
            return loginfoMapper.updateByPrimaryKeySelective((Loginfo)record);
        }else if(record instanceof Logopera){
            return logoperaMapper.updateByPrimaryKeySelective((Logopera)record);
        }else{
            throw new Exception("");
        }
    }

    @Override
    public int deleteByPrimaryKey(DataRecode record) throws Exception{
        if(record instanceof Loginfo){
            return loginfoMapper.deleteByPrimaryKey(((Loginfo) record).getId());
        }else if(record instanceof Logopera){
            return logoperaMapper.deleteByPrimaryKey(((Logopera) record).getId());
        }else{
            throw new Exception("");
        }
    }

    @Override
    public List selectData(DataRecode record) throws Exception{
        Date starTime;
        Date endTime;
        String moduleName;
        String logType;
        String logInfo;
        Integer opStatus;
        if(record instanceof LogInfoQueryParam){
            starTime = ((LogInfoQueryParam) record).getStarTime();
            endTime = ((LogInfoQueryParam) record).getEndtime();
            moduleName = ((LogInfoQueryParam) record).getModuleName();
            logType = ((LogInfoQueryParam) record).getLogType();
            logInfo = ((LogInfoQueryParam) record).getLogInfo();
            opStatus = ((LogInfoQueryParam) record).getOpstatus();
            return  loginfoMapper.selectLog(starTime,endTime,moduleName,logType,logInfo,opStatus);
        }else if(record instanceof LogoperaQueryParam){
            starTime = ((LogoperaQueryParam) record).getStarTime();
            endTime = ((LogoperaQueryParam) record).getEndtime();
            moduleName = ((LogoperaQueryParam) record).getModuleName();
            logType = ((LogoperaQueryParam) record).getLogType();
            logInfo = ((LogoperaQueryParam) record).getLogInfo();
            opStatus = ((LogoperaQueryParam) record).getOpstatus();
            return logoperaMapper.selectLog(starTime,endTime,moduleName,logType,logInfo,opStatus);
        }else{
            throw new Exception("");
        }
    }
}
